package com.atguigu.lease.common.excetion;
import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice // 全局异常 监听的注解
public class GlobalException {
    //此注解是让SpringBoot知道遇到什么样的异常，会调用此方法进行处理
    @ExceptionHandler(Exception.class)
    public <T>Result<T> handleException(Exception e){
        e.printStackTrace();
        return Result.fail();
    }

    @ExceptionHandler(LeaseException.class)
    public <T>Result<T> handleBusinessException(LeaseException e){
        e.printStackTrace();
        return Result.build(e.getCode(),e.getMessage());
    }
}
